package com.zw.cloud.mybatis.plus.controller.stenter;


import com.google.common.collect.Lists;
import com.zw.cloud.mybatis.plus.entity.stenter.OperatorInfoDTO;
import com.zw.cloud.mybatis.plus.entity.stenter.ProductRecordDetail;
import com.zw.cloud.mybatis.plus.service.api.stenter.IProductRecordDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 生产记录关联表 前端控制器
 * </p>
 *
 * @author zw
 * @since 2023-10-31
 */
@RestController
@RequestMapping("/product-record-detail")
public class ProductRecordDetailController {

    @Autowired
    private IProductRecordDetailService productRecordDetailService;

    @GetMapping
    public Boolean onDuplicateKeyUpdate() {
        return productRecordDetailService.onDuplicateKeyUpdate(Lists.newArrayList(buildProductRecordDetail()));
    }

    @GetMapping("/saveOrUpdateBatch")
    public Boolean saveOrUpdateBatch() {
        return productRecordDetailService.saveOrUpdateBatch(Lists.newArrayList(buildProductRecordDetail()));
    }

    @GetMapping("/batchUpdateBaseTenterCraftId/{id}")
    public Boolean batchUpdateBaseTenterCraftId(@PathVariable Long id) {
        return productRecordDetailService.batchUpdateBaseTenterCraftId(Lists.newArrayList(id),1L);
    }

    private ProductRecordDetail buildProductRecordDetail() {
        ProductRecordDetail productRecordDetail = new ProductRecordDetail();
        productRecordDetail.setId(2L);
        productRecordDetail.setProductRecordId(1L);
        productRecordDetail.setPullReason("setPullReason");
        productRecordDetail.setUpperWeftDensity("setUpperWeftDensity");
        productRecordDetail.setClothCarRegion("setClothCarRegion");
        productRecordDetail.setUrgentStatus(0);
        productRecordDetail.setLowerWarpDensity("setLowerWarpDensity");
        OperatorInfoDTO operatorInfoDTO = new OperatorInfoDTO("001","zw");
        productRecordDetail.setInspectorInfo(Lists.newArrayList(operatorInfoDTO));

        return productRecordDetail;
    }

}
